<?php
/**
 * @package		Zaragoza Face and Tweet
 * @license		GNU/GPL 2.0 http://www.gnu.org/licenses/gpl-2.0.html
 * @Copyright (c) 2010 Ciro Artigot
 * @author		Ciro Artigot <info@zaragozaonline.com>
 
 */

defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.plugin.plugin' );

//$mainframe->registerEvent('onBeforeDisplayContent', 'plgContentZaragoza_Faceandtweet');

class plgContentZaragoza_faceandtweet extends JPlugin {



    function onAfterDisplayContent(&$article, &$params, $page=0) {

            global $mainframe;

            if(JRequest::getVar('view','')=='article')
            {
                $url = "http://".$_SERVER['HTTP_HOST'] . getenv('REQUEST_URI');
            }
            else
            {
                if(isset($article->id))
                {
                    $url = "http://".$_SERVER['HTTP_HOST'].JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catslug, $article->sectionid));

                }
                else
                {
                    return;
                }
            }
            
            $url2 = urlencode($url);

            $plugin =& JPluginHelper::getPlugin('content', 'zaragoza_faceandtweet');
            $cp = new JParameter( $plugin->params );

            $like = '';  $retweet = '';

            $cp = new JParameter( $plugin->params );

            if($cp->get('like',1))
            {
                $like = '<div class="faceandtweet_like" style="float:'.$cp->get('float','left').'; width:'.$cp->get('like_width','200').'px; height:'.$cp->get('like_height','40').'px;">'
                       .'<iframe src="http://www.facebook.com/plugins/like.php?href='.$url2 .'&amp;layout='.$cp->get('like_style','button_count').'&amp;width='.$cp->get('like_width','200').'&amp;show_faces=false&amp;action='.$cp->get('like_verb','like').'&amp;colorscheme='.$cp->get('like_color_scheme','light').'&amp;height='.$cp->get('like_height','40').'" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:'.$cp->get('like_width','200').'px; height:'.$cp->get('like_height','40').'px;" allowTransparency="true">'
                       .'</iframe></div>'
                       ;

            }

            if($cp->get('retweet',1))
            {
                $retweet = '<div class="faceandtweet_retweet" style="float:'.$cp->get('float','left').'; width:65px; padding-top:2px;">'
                          .'<script type="text/javascript">'
                          .'tweetmeme_style = '."'".'compact'."'".';tweetmeme_url = '."'".$url."'".';'
                          .'</script>'
                          .'<script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script>'
                          .'</div>';
            }

            $gplus = '<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>';
            $gplus .= '<g:plusone size="medium" count="true" href="'.$url.'"></g:plusone>';

            if($cp->get('order',1))
            {
                $dos = $like.$retweet.$gplus;
            }
            else
            {
                $dos = $retweet.$like.$gplus ;
            }

            if(!$cp->get('where',1)&&JRequest::getVar('view','')!='article') return;
            $title = '<p style="border-bottom: 1px solid #E0E0E0;font-weight: bold;">Share</p>';
            if($cp->get('position',1))
            {
                $tweet =  '<div class="faceandtweet">'.$title.$dos.'<div style="clear:both;"></div></div>';

            }
            else
            {
                $tweet =  '<div class="faceandtweet" style="width:240px; float:left; margin-bottom:8px;">'.$title.$dos.'<div style="clear:both;"></div></div>';

            }
            
            return $tweet;
    }

}



?>